package com.nys.cqhttp.message.factory.impl;

import cn.hutool.http.HttpUtil;
import com.nys.cqhttp.mapper.*;
import com.nys.cqhttp.message.factory.IMessageHandler;
import com.nys.cqhttp.model.*;
import com.nys.cqhttp.param.Context;
import com.nys.cqhttp.param.MessageParam;
import com.nys.cqhttp.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.File;
import java.util.*;

/**
 * DirectUrlMessageHandler
 *
 * @author nysheng
 * @version 1.0.0
 * @description 冒险
 * @date 2021/12/28 19:53
 */
@Slf4j
@Component
public class MXMessageHandler implements IMessageHandler {
  @Autowired private TheMessageMapper theMessageMapper;
  @Autowired private MessageLogMapper messageLogMapper;
  @Autowired private EventConfigMapper eventConfigMapper;
  @Autowired private BoosConfigMapper boosConfigMapper;
  @Autowired private UserStateMapper userStateMapper;
  @Autowired private UserBackpackMapper userBackpackMapper;
  @Autowired private YuanShenMapper yuanShenMapper;
  @Autowired private YuanShenConfigMapper yuanShenConfigMapper;
  @Autowired private MassageMapper massageMapper;
  private static MXMessageHandler mxMessageHandler;

  @Autowired private SysUserMapper sysUserMapper;
  private static String at = "[CQ:at,qq=";
  private static String at1 = "]";

  @PostConstruct
  public void init() throws Exception {
    mxMessageHandler = this;
    theMessageMapper = this.theMessageMapper;
    sysUserMapper = this.sysUserMapper;
    messageLogMapper = this.messageLogMapper;
    eventConfigMapper = this.eventConfigMapper;
    boosConfigMapper = this.boosConfigMapper;
    userStateMapper = this.userStateMapper;
    userBackpackMapper = this.userBackpackMapper;
    yuanShenMapper=this.yuanShenMapper;
    yuanShenConfigMapper = this.yuanShenConfigMapper;
    massageMapper = this.massageMapper;
  }

  @Override
  public List<String> listHandler(Massage messagePojo, Context context) {
    return Arrays.asList(handler(messagePojo, context));
  }

  @Override
  public String handler(Massage messagePojo, Context context) {
    try {
      MessageParam messageParam = context.getMessageParam();
      String message = messageParam.getMessage();
      String senderId = messageParam.getSenderId();
      String selfId = messageParam.getSelfId();
      //      String[] split = message.split("-");
      Random random = new Random();
      SysUserExample sysUserExample = new SysUserExample();
      SysUserExample.Criteria criteria1 = sysUserExample.createCriteria();
      criteria1.andJqrQqEqualTo(selfId);
      criteria1.andUserQqEqualTo(senderId);
      List<SysUser> sysUsers = mxMessageHandler.sysUserMapper.selectByExample(sysUserExample);
      if (CollectionUtils.isEmpty(sysUsers)) {
        return at + messageParam.getSenderId() + at1 + "当前QQ未创建账号,请发送'签到'创建账号!";
      }
      SysUser sysUser = sysUsers.get(0);
      if (message.equals("冒险")) {
        MessageLogExample messageLogExample = new MessageLogExample();
        MessageLogExample.Criteria criteria3 = messageLogExample.createCriteria();
        criteria3.andJqrQqEqualTo(selfId);
        criteria3.andUserQqEqualTo(senderId);
        criteria3.andMessageLike("冒险-");
        criteria3.andSendDateGreaterThan(DateUtils.getNowDayStart());
        List<MessageLog> messageLogs =
            mxMessageHandler.messageLogMapper.selectByExample(messageLogExample);
        if (CollectionUtils.isNotEmpty(messageLogs)) {
          return at + messageParam.getSenderId() + at1 + "今日已冒险!";
        } else {
          MessageLog messageLog = new MessageLog();
          messageLog.setMessage("冒险-");
          messageLog.setJqrQq(selfId);
          messageLog.setUserQq(senderId);
          messageLog.setSendDate(new Date());
          mxMessageHandler.messageLogMapper.insertSelective(messageLog);
          UserState userState1 = new UserState();
          userState1.setUserQq(senderId);
          userState1.setJqrQq(selfId);
          userState1.setAttack(sysUser.getAttack());
          userState1.setLife(sysUser.getLife());
          userState1.setSendDate(new Date());
          mxMessageHandler.userStateMapper.insertSelective(userState1);
          UserStateExample userStateExample = new UserStateExample();
          UserStateExample.Criteria criteria2 = userStateExample.createCriteria();
          criteria2.andJqrQqEqualTo(selfId);
          criteria2.andUserQqEqualTo(senderId);
          criteria2.andSendDateGreaterThan(DateUtils.getNowDayStart());
          List<UserState> userStates =
              mxMessageHandler.userStateMapper.selectByExample(userStateExample);
          UserState userState = userStates.get(0);
          int i = random.nextInt(1);
          if (i == 0) {
            EventConfigExample eventConfigExample = new EventConfigExample();
            EventConfigExample.Criteria criteria = eventConfigExample.createCriteria();
            criteria.andJqrQqEqualTo(selfId);
            List<EventConfig> eventConfigs =
                mxMessageHandler.eventConfigMapper.selectByExample(eventConfigExample);
            EventConfig eventConfig = eventConfigs.get(random.nextInt(eventConfigs.size()));
            String res = eventConfig.getMassage();
            if (eventConfig.getSpirit() != 0) {
              sysUser.setSpirit(sysUser.getSpirit() + eventConfig.getSpirit());
              mxMessageHandler.sysUserMapper.updateByPrimaryKeySelective(sysUser);
            }
            if (eventConfig.getGold() != 0) {
              userState.setGold(userState.getGold() + eventConfig.getGold());
            }
            if (eventConfig.getLife() != 0) {
              userState.setLife(userState.getLife() + eventConfig.getLife());
            }
            if (eventConfig.getAttack() != 0) {
              userState.setAttack(userState.getAttack() + eventConfig.getAttack());
            }
            if (eventConfig.getPlainBait() != 0) {
              userState.setPlainBait(userState.getPlainBait()+eventConfig.getPlainBait());
            }
            if (eventConfig.getPremiumBait() != 0) {
              userState.setPremiumBait(userState.getPremiumBait()+eventConfig.getPremiumBait());
            }
            if (eventConfig.getBoutiqueBait() != 0) {
              userState.setBoutiqueBait(userState.getBoutiqueBait()+eventConfig.getBoutiqueBait());
            }
            if (userState.getLife() <= 0) {
              res += "\n您已死亡!已强制退出冒险";
              if (userState.getGold() > 0) {
                userState.setGold(0);
              }
              if (userState.getCard() > 0) {
                userState.setCard(0);
              }
              if (userState.getPlainBait() != 0) {
                userState.setPlainBait(0);
              }
              if (userState.getPremiumBait() != 0) {
                userState.setPremiumBait(0);
              }
              if (userState.getBoutiqueBait() != 0) {
                userState.setBoutiqueBait(0);
              }
              sysUser.setGold(sysUser.getGold() + userState.getGold() + (userState.getCard() * 10));
              mxMessageHandler.sysUserMapper.updateByPrimaryKeySelective(sysUser);
              MessageLog messageLog1 = new MessageLog();
              messageLog1.setMessage("结束冒险-");
              messageLog1.setJqrQq(selfId);
              messageLog1.setUserQq(senderId);
              messageLog1.setSendDate(new Date());
              mxMessageHandler.messageLogMapper.insertSelective(messageLog1);
            } else {
              res += "\n发送'继续冒险'即可继续! 发送'结束冒险'即可结束!";
            }
            mxMessageHandler.userStateMapper.updateByPrimaryKeySelective(userState);

            return at + messageParam.getSenderId() + at1 + res;
          } else {
            return at
                + messageParam.getSenderId()
                + at1
                + combat(sysUser, selfId, senderId, messageParam);
          }
        }

      } else if (message.equals("继续冒险")) {
        MessageLogExample messageLogExample = new MessageLogExample();
        MessageLogExample.Criteria criteria3 = messageLogExample.createCriteria();
        criteria3.andJqrQqEqualTo(selfId);
        criteria3.andUserQqEqualTo(senderId);
        criteria3.andMessageLike("冒险-");
        criteria3.andSendDateGreaterThan(DateUtils.getNowDayStart());
        List<MessageLog> messageLogs =
            mxMessageHandler.messageLogMapper.selectByExample(messageLogExample);
        if (CollectionUtils.isNotEmpty(messageLogs)) {
          MessageLogExample messageLogExample1 = new MessageLogExample();
          MessageLogExample.Criteria criteria4 = messageLogExample1.createCriteria();
          criteria4.andJqrQqEqualTo(selfId);
          criteria4.andUserQqEqualTo(senderId);
          criteria4.andMessageLike("结束冒险-");
          criteria4.andSendDateGreaterThan(DateUtils.getNowDayStart());
          List<MessageLog> messageLogs1 =
              mxMessageHandler.messageLogMapper.selectByExample(messageLogExample1);
          if (CollectionUtils.isNotEmpty(messageLogs1)) {
            return at + messageParam.getSenderId() + at1 + "今日冒险已结束";
          }
          int i = random.nextInt(3);
          if (i == 0) {
            EventConfigExample eventConfigExample = new EventConfigExample();
            EventConfigExample.Criteria criteria = eventConfigExample.createCriteria();
            criteria.andJqrQqEqualTo(selfId);
            List<EventConfig> eventConfigs =
                mxMessageHandler.eventConfigMapper.selectByExample(eventConfigExample);
            EventConfig eventConfig = eventConfigs.get(random.nextInt(eventConfigs.size()));
            if (eventConfig.getSpirit() > 0) {
              sysUser.setSpirit(sysUser.getSpirit() + eventConfig.getSpirit());
              mxMessageHandler.sysUserMapper.updateByPrimaryKeySelective(sysUser);
            }
            UserStateExample userStateExample = new UserStateExample();
            UserStateExample.Criteria criteria2 = userStateExample.createCriteria();
            criteria2.andJqrQqEqualTo(selfId);
            criteria2.andUserQqEqualTo(senderId);
            criteria2.andSendDateGreaterThan(DateUtils.getNowDayStart());
            List<UserState> userStates =
                mxMessageHandler.userStateMapper.selectByExample(userStateExample);
            if (CollectionUtils.isEmpty(userStates)) {
              return at + messageParam.getSenderId() + at1 + "你未开始冒险!请发'冒险'开始游戏";
            }
            UserState userState = userStates.get(0);
            String res = eventConfig.getMassage();
            if (eventConfig.getSpirit() != 0) {
              sysUser.setSpirit(sysUser.getSpirit() + eventConfig.getSpirit());
              mxMessageHandler.sysUserMapper.updateByPrimaryKeySelective(sysUser);
            }

            if (eventConfig.getGold() != 0) {
              userState.setGold(userState.getGold() + eventConfig.getGold());
            }
            if (eventConfig.getLife() != 0) {
              userState.setLife(userState.getLife() + eventConfig.getLife());
            }
            if (eventConfig.getAttack() != 0) {
              userState.setAttack(userState.getAttack() + eventConfig.getAttack());
            }
            if (eventConfig.getPlainBait() != 0) {
              userState.setPlainBait(userState.getPlainBait()+eventConfig.getPlainBait());
            }
            if (eventConfig.getPremiumBait() != 0) {
              userState.setPremiumBait(userState.getPremiumBait()+eventConfig.getPremiumBait());
            }
            if (eventConfig.getBoutiqueBait() != 0) {
              userState.setBoutiqueBait(userState.getBoutiqueBait()+eventConfig.getBoutiqueBait());
            }
            if (userState.getLife() <= 0) {
              res += "\n您已死亡!已强制退出冒险";
              if (userState.getGold() > 0) {
                userState.setGold(0);
              }
              if (userState.getCard() > 0) {
                userState.setCard(0);
              }
              if (userState.getPlainBait() != 0) {
                userState.setPlainBait(0);
              }
              if (userState.getPremiumBait() != 0) {
                userState.setPremiumBait(0);
              }
              if (userState.getBoutiqueBait() != 0) {
                userState.setBoutiqueBait(0);
              }
              sysUser.setGold(sysUser.getGold() + userState.getGold() + (userState.getCard() * 10));
              mxMessageHandler.sysUserMapper.updateByPrimaryKeySelective(sysUser);
              MessageLog messageLog = new MessageLog();
              messageLog.setMessage("结束冒险-");
              messageLog.setJqrQq(selfId);
              messageLog.setUserQq(senderId);
              messageLog.setSendDate(new Date());
              mxMessageHandler.messageLogMapper.insertSelective(messageLog);
            } else {
              res += "\n发送'继续冒险'即可继续! 发送'结束冒险'即可结束!";
            }
            mxMessageHandler.userStateMapper.updateByPrimaryKeySelective(userState);
            return at + messageParam.getSenderId() + at1 + res;
          } else {
            return at
                + messageParam.getSenderId()
                + at1
                + combat(sysUser, selfId, senderId, messageParam);
          }
        }
      } else if (message.equals("结束冒险")) {
        String res = "";
        MessageLogExample messageLogExample = new MessageLogExample();
        MessageLogExample.Criteria criteria3 = messageLogExample.createCriteria();
        criteria3.andJqrQqEqualTo(selfId);
        criteria3.andUserQqEqualTo(senderId);
        criteria3.andMessageLike("冒险-");
        criteria3.andSendDateGreaterThan(DateUtils.getNowDayStart());
        List<MessageLog> messageLogs =
            mxMessageHandler.messageLogMapper.selectByExample(messageLogExample);

        if (CollectionUtils.isNotEmpty(messageLogs)) {
          MessageLogExample messageLogExample1 = new MessageLogExample();
          MessageLogExample.Criteria criteria31 = messageLogExample1.createCriteria();
          criteria31.andJqrQqEqualTo(selfId);
          criteria31.andUserQqEqualTo(senderId);
          criteria31.andMessageLike("结束冒险-");
          criteria31.andSendDateGreaterThan(DateUtils.getNowDayStart());
          List<MessageLog> messageLogs1 =
              mxMessageHandler.messageLogMapper.selectByExample(messageLogExample1);
          if (CollectionUtils.isNotEmpty(messageLogs1)) {
            return at + messageParam.getSenderId() + at1 + "今日冒险已结束";
          }
          UserStateExample userStateExample = new UserStateExample();
          UserStateExample.Criteria criteria2 = userStateExample.createCriteria();
          criteria2.andJqrQqEqualTo(selfId);
          criteria2.andUserQqEqualTo(senderId);
          criteria2.andSendDateGreaterThan(DateUtils.getNowDayStart());
          List<UserState> userStates =
              mxMessageHandler.userStateMapper.selectByExample(userStateExample);

          if (CollectionUtils.isEmpty(userStates)) {
            return at + messageParam.getSenderId() + at1 + "你未开始冒险!请发'冒险'开始游戏";
          }
          MessageLog messageLog = new MessageLog();
          messageLog.setMessage("结束冒险-");
          messageLog.setJqrQq(selfId);
          messageLog.setUserQq(senderId);
          messageLog.setSendDate(new Date());
          mxMessageHandler.messageLogMapper.insertSelective(messageLog);
          UserState userState = userStates.get(0);
          Integer gold = userState.getGold();
          if (userState.getCard() <= 0) {
            gold += (userState.getCard() * 10);
            res = "战果:金币:" + gold + " 卡片: 无" +" 普通鱼饵:"+userState.getPlainBait()
                    +" 优质鱼饵:"+userState.getPremiumBait()
                    +" 精品鱼饵:"+userState.getBoutiqueBait();
          } else {
            MassageExample massageExample = new MassageExample();
            MassageExample.Criteria criteria5 = massageExample.createCriteria();
            criteria5.andUserEqualTo(messageParam.getSelfId());
            criteria5.andKeywordEqualTo("原神抽卡");
            List<Massage> massages = mxMessageHandler.massageMapper.selectByExample(massageExample);
            File file = new File(massages.get(0).getValue());
            // File file = new File("D:/img/原神抽卡");
            File[] files = file.listFiles();
            List<String> nameList = new ArrayList<>();
            for (Integer i = 0; i < userState.getCard(); i++) {
              File file1 = files[random.nextInt(files.length)];
              String name = file1.getName().substring(0, file1.getName().indexOf("."));
              if (name.equals("原神")) {
                i--;
              } else {
                nameList.add(name);
              }
            }
            res = "战果:金币:" + gold + " 卡片:";
            for (String name : nameList) {
              res += name + " ";
              YuanShenExample yuanShenExample = new YuanShenExample();
              YuanShenExample.Criteria criteria = yuanShenExample.createCriteria();
              criteria.andJqrQqEqualTo(messageParam.getSelfId());
              criteria.andUserQqEqualTo(messageParam.getSenderId());
              criteria.andNameEqualTo(name);
              List<YuanShen> yuanShens =
                      mxMessageHandler.yuanShenMapper.selectByExample(yuanShenExample);
              if (CollectionUtils.isEmpty(yuanShens)) {
                YuanShen yuanShen = new YuanShen();
                yuanShen.setJqrQq(messageParam.getSelfId());
                yuanShen.setUserQq(messageParam.getSenderId());
                yuanShen.setName(name);
                yuanShen.setStar(1);
                mxMessageHandler.yuanShenMapper.insertSelective(yuanShen);
              } else {
                YuanShen yuanShen = yuanShens.get(0);
                yuanShen.setStar(yuanShen.getStar() + 1);
                mxMessageHandler.yuanShenMapper.updateByPrimaryKeySelective(yuanShen);
              }
            }
            YuanShenExample yuanShenExample = new YuanShenExample();
            YuanShenExample.Criteria criteria = yuanShenExample.createCriteria();
            criteria.andJqrQqEqualTo(messageParam.getSelfId());
            criteria.andUserQqEqualTo(messageParam.getSenderId());
            List<YuanShen> yuanShens =
                    mxMessageHandler.yuanShenMapper.selectByExample(yuanShenExample);
            Integer myLife = 1000;
            Integer myAttack = 100;
            Integer myMilitaryStrength = 2000;
            for (YuanShen myYuanShen : yuanShens) {
              YuanShenConfig yuanShenConfig =
                      mxMessageHandler.yuanShenConfigMapper.selectByPrimaryKey(myYuanShen.getName());
              myLife += yuanShenConfig.getLife();
              myAttack += yuanShenConfig.getAttack();
              myMilitaryStrength += yuanShenConfig.getMilitaryStrength();
              if (myYuanShen.getStar() > 1) {
                myLife += (yuanShenConfig.getLevelLife() * (myYuanShen.getStar() - 1));
                myAttack += (yuanShenConfig.getLevelAttack() * (myYuanShen.getStar() - 1));
                myMilitaryStrength +=
                        (yuanShenConfig.getLevelMilitaryStrength() * (myYuanShen.getStar() - 1));
              }
            }
            sysUser.setAttack(myAttack);
            sysUser.setLife(myLife);
            sysUser.setMilitaryStrength(myMilitaryStrength);

            if (nameList.size() == 0) {
              res += "无";
            }
            res+= " 普通鱼饵:"+userState.getPlainBait()
                    +" 优质鱼饵:"+userState.getPremiumBait()
                    +" 精品鱼饵:"+userState.getBoutiqueBait();
          }
          sysUser.setGold(sysUser.getGold() + gold);
          mxMessageHandler.sysUserMapper.updateByPrimaryKeySelective(sysUser);
          UserBackpackExample userBackpackExample = new UserBackpackExample();
          UserBackpackExample.Criteria criteria = userBackpackExample.createCriteria();
          criteria.andJqrQqEqualTo(messageParam.getSelfId());
          criteria.andUserQqEqualTo(messageParam.getSenderId());
          List<UserBackpack> userBackpacks =
              mxMessageHandler.userBackpackMapper.selectByExample(userBackpackExample);

          if (CollectionUtils.isEmpty(userBackpacks)) {
            UserBackpack userBackpack = new UserBackpack();
            userBackpack.setJqrQq(messageParam.getSelfId());
            userBackpack.setUserQq(messageParam.getSenderId());
            userBackpack.setBoutiqueBait(userState.getBoutiqueBait());
            userBackpack.setPremiumBait(userState.getPremiumBait());
            userBackpack.setPlainBait(userState.getPlainBait());
            mxMessageHandler.userBackpackMapper.insertSelective(userBackpack);
          } else {
            UserBackpack userBackpack = userBackpacks.get(0);
            userBackpack.setBoutiqueBait(
                userBackpack.getBoutiqueBait() + userState.getBoutiqueBait());
            userBackpack.setPremiumBait(userBackpack.getPremiumBait() + userState.getPremiumBait());
            userBackpack.setPlainBait(userBackpack.getPlainBait() + userState.getPlainBait());
            mxMessageHandler.userBackpackMapper.updateByPrimaryKeySelective(userBackpack);
          }
          return at + messageParam.getSenderId() + at1 + res;
        } else {
          return at + messageParam.getSenderId() + at1 + "你未开始冒险!请发'冒险'开始游戏";
        }
      } else if (message.equals("冒险战果")) {
        UserStateExample userStateExample = new UserStateExample();
        UserStateExample.Criteria criteria2 = userStateExample.createCriteria();
        criteria2.andJqrQqEqualTo(selfId);
        criteria2.andUserQqEqualTo(senderId);
        criteria2.andSendDateGreaterThan(DateUtils.getNowDayStart());
        List<UserState> userStates =
            mxMessageHandler.userStateMapper.selectByExample(userStateExample);
        if (CollectionUtils.isEmpty(userStates)) {
          return at + messageParam.getSenderId() + at1 + "今日未冒险!";
        }
        UserState userState = userStates.get(0);
        return at
            + messageParam.getSenderId()
            + at1
            + "金币:"
            + userState.getGold()
            + "卡片:"
            + userState.getCard()
            + " 普通鱼饵:"
            + userState.getPlainBait()
            + " 优质鱼饵:"
            + userState.getPremiumBait()
            + " 精品鱼饵:"
            + userState.getBoutiqueBait();
      }
      return "111111111111111";
    } catch (Exception e) {
      e.printStackTrace();
      return e.getMessage();
    }
  }

  public String combat(SysUser sysUser, String selfId, String senderId, MessageParam messageParam) {
    UserStateExample userStateExample = new UserStateExample();
    UserStateExample.Criteria criteria2 = userStateExample.createCriteria();
    criteria2.andJqrQqEqualTo(selfId);
    criteria2.andUserQqEqualTo(senderId);
    criteria2.andSendDateGreaterThan(DateUtils.getNowDayStart());
    List<UserState> userStates = mxMessageHandler.userStateMapper.selectByExample(userStateExample);
    if (CollectionUtils.isEmpty(userStates)) {
      return "你未开始冒险!请发'冒险'开始游戏";
    }
    UserState userState = userStates.get(0);

    Random r = new Random();
    BoosConfigExample boosConfigExample = new BoosConfigExample();
    BoosConfigExample.Criteria criteria = boosConfigExample.createCriteria();
    criteria.andJqrQqEqualTo(selfId);
    List<BoosConfig> boosConfigs =
        mxMessageHandler.boosConfigMapper.selectByExample(boosConfigExample);
    BoosConfig boosConfig = boosConfigs.get(r.nextInt(boosConfigs.size()));
    String str = "只因使出唱跳rap(生命值+1000),并对你发出律师函(金币-10)";
    String str1 = "只因:你干嘛~哎哟~ 只因逃出了现场!";
    String res2 = "冒险遇到了" + boosConfig.getName() + "(战力" + boosConfig.getMilitaryStrength() + ")";
    String res = "";
    int myLife = (int) (sysUser.getLife() * ((sysUser.getSpirit() * 1.0 / 100)));
    Integer enemyLife = boosConfig.getLife();
    int myAttack = (int) (sysUser.getAttack() * ((sysUser.getSpirit() * 1.0) / 100));
    Integer enemyAttack = boosConfig.getAttack();
    for (int i = 1; myLife > 0 && enemyLife > 0; i++) {
      res += "第" + i + "回合:\\n";
      if (boosConfig.getName().equals("只因")) {
        if (i >= 11) {
          res += str1;
          break;
        }
        res += str;
        userState.setGold(userState.getGold() - 10);
        enemyLife += 1000;
      }
      int theMyAttack = r.nextInt(myAttack);
      int theEnemyAttack = enemyAttack <= 0 ? 0 : r.nextInt(enemyAttack);
      int l = myLife - theEnemyAttack;
      int l2 = enemyLife - theMyAttack;
      if (l > 0) {
        myLife -= theEnemyAttack;
      } else {
        myLife = 0;
        res += "\\n你的生命: " + myLife + "敌方生命: " + enemyLife;
        break;
      }
      if (l2 > 0) {
        enemyLife -= theMyAttack;
      } else {
        enemyLife = 0;
        res += "\\n你的生命: " + myLife + "敌方生命: " + enemyLife;
        break;
      }
      res += "\\n你的生命: " + myLife + "敌方生命: " + enemyLife;
    }
    userState.setLife(myLife);
    if (myLife > 0) {
      userState.setGold(userState.getGold() + boosConfig.getGold());
      userState.setCard(userState.getCard() + boosConfig.getCard());
    }
    HttpUtil.post(
        messageParam.getUrl() + "/send_group_forward_msg",
        "{\n"
            + "    \"group_id\": \""
            + messageParam.getGroupId()
            + "\",\n"
            + "    \"messages\": [\n"
            + "        {\n"
            + "            \"type\": \"node\",\n"
            + "            \"data\": {\n"
            + "                \"user_id\": \""
            + messageParam.getSelfId()
            + "\",\n"
            + "                \"nickname\": \"云梦星机器人\",\n"
            + "                \"content\":\""
            + messageParam.getSenderId()
            + res2
            + "\"\n"
            + "            }\n"
            + "        },\n"
            + "        {\n"
            + "            \"type\": \"node\",\n"
            + "            \"data\": {\n"
            + "                \"user_id\": \""
            + messageParam.getSelfId()
            + "\",\n"
            + "                \"nickname\": \"云梦星机器人\",\n"
            + "                \"content\":\""
            + at
            + messageParam.getSenderId()
            + at1
            + res
            + "\"\n"
            + "            }\n"
            + "        }\n"
            + "    ]\n"
            + "}");
    if (myLife == 0) {

      userState.setPremiumBait(0);
      userState.setPlainBait(0);
      userState.setBoutiqueBait(0);
      if (userState.getGold() > 0) {
        userState.setGold(0);
      }
      if (userState.getCard() > 0) {
        userState.setCard(0);
      }
      sysUser.setGold(sysUser.getGold() + userState.getGold() + (userState.getCard() * 10));
      mxMessageHandler.sysUserMapper.updateByPrimaryKeySelective(sysUser);
      MessageLog messageLog = new MessageLog();
      messageLog.setMessage("结束冒险-");
      messageLog.setJqrQq(selfId);
      messageLog.setUserQq(senderId);
      messageLog.setSendDate(new Date());
      mxMessageHandler.messageLogMapper.insertSelective(messageLog);
    }
    mxMessageHandler.userStateMapper.updateByPrimaryKeySelective(userState);
    return "\n当前战果:金币:"
        + userState.getGold()
        + " 卡片:"
        + userState.getCard()
        + " 普通鱼饵:"
        + userState.getPlainBait()
        + " 优质鱼饵:"
        + userState.getPremiumBait()
        + " 精品鱼饵:"
        + userState.getBoutiqueBait()
        + (myLife > 0 ? "\n发送'继续冒险'即可继续! 发送'结束冒险'即可结束!" : "\n您已死亡!已强制退出冒险");
  }
}
